package com.arturjaneczko.services.impl;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.URL;

import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.UIManager;

import com.arturjaneczko.ResourceUtil;

public enum EIcon {

	DEFAULT(""),
	TEST_ICON("com.arturjaneczko.view.impl.label.icon"),
	
	TEXT("com.arturjaneczko.view.impl.clipboard.component.clipboardobjecticonview.label.text"),
	FILES("com.arturjaneczko.view.impl.clipboard.component.clipboardobjecticonview.label.files"),
	GRAPHICS("com.arturjaneczko.view.impl.clipboard.component.clipboardobjecticonview.label.graphics"),
	NOT_SUPPORTED("com.arturjaneczko.view.impl.clipboard.component.clipboardobjecticonview.label.nosupported");

	private String path;
	private static final String ICONS_RESOURCE = "icons/";

	private EIcon(String path) {
		this.path = path;
	}

	private URL getIconUrl() throws FileNotFoundException, IOException {
		return ResourceUtil.getRelativeUrl(this, ICONS_RESOURCE + P.r(path));
	}
	
	public Icon getIcon() {
		Icon icon = null;
		Icon defaultIcon = UIManager.getIcon("OptionPane.questionIcon");
		try {
			icon = getIconUrl() != null ? icon = new ImageIcon(getIconUrl()) : defaultIcon;
		} catch (IOException e) {
			icon = defaultIcon;
		}
		return icon;
	}
	
	public Icon getSystemIcon(String key) {
		switch(key) {
		case "F":
			return UIManager.getIcon("FileView.fileIcon");
		case "G":
			return UIManager.getIcon("FileView.directoryIcon");
		case "T":
			return UIManager.getIcon("FileView.computerIcon");
		default:
			return UIManager.getIcon("OptionPane.questionIcon");
		}
	}

}
